Repository navigation
fix(id): uniquify colliding upload stored names - #1696
Conversation
upload_handler set the blob tag under the supplied filename unconditionally, so a second paste named image.png silently re-pointed the name at the new blob and un-named the first image. Per the triage ruling on #1549 (archive-first rejected: it renames the FIRST image), the handler now resolves the stored name after the blob hash is known: the intended name is kept when free or already naming the same blob (idempotent re-upload of identical bytes); when a different blob owns it, the upload is stored as stem-N.ext with the smallest free N >= 1. The paste-{secs} fallback passes through the same uniquifier. Tag, filename-keyed metadata, and UploadResponse name/url all use the stored name. Regression tests: two same-name uploads with different bytes (both listed and resolvable, first name still resolves to the first hash, second response carries image-1.png, identical re-upload idempotent) and two nameless uploads never sharing a stored name.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 7 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4d423fbdff
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| match upload_name_owner(store, &candidate).await? { | ||
| None => return Ok(candidate), | ||
| Some(owner) if owner == hash => return Ok(candidate), |
There was a problem hiding this comment.
Reserve the chosen upload name atomically
When two uploads with different bytes and the same intended filename overlap, both can observe the same candidate as free before either handler reaches tags().set(). Both then return that name successfully, but the last tag write silently removes the other image's name and listing—the data-loss scenario this change intends to prevent. This also affects suffix candidates when the original name is already occupied. The upload route has no serialization, and the web client's paste/drop handlers launch uploads concurrently. Make name selection and tag assignment atomic, or serialize the lookup-and-set sequence with a shared lock; the sequential tests do not cover this interleaving.
Useful? React with 👍 / 👎.
Fixes #1549.
Problem
upload_handlerset the blob tag under the supplied filename unconditionally, so a second paste namedimage.pngsilently re-pointed the name at the new blob — the first image lost its name.Fix (
pkgs/id/src/web/routes.rs, per the triage ruling on #1549)Archive-first was rejected in triage (it renames the FIRST image out from under existing name lookups). Instead, after the blob hash is known, the handler resolves the stored name:
-Nsuffix).stem-N.extwith the smallest free N ≥ 1.paste-{secs}fallback passes through the same uniquifier, so two nameless uploads in the same second never share a stored name.The tag, all filename-keyed metadata records, and the
UploadResponsename/url all use the stored name. No change to document save semantics or the/blob/{hash}URL shape.Tests
upload_same_name_different_bytes_uniquifies_second(both images listed and resolvable, first name still resolves to the first hash, second response carriesimage-1.png, identical re-upload idempotent) andupload_nameless_uploads_never_share_a_stored_name.cargo test --features web --lib web::routes::upload_router_tests— 12 passed, 0 failed. CI is the verification of record for the full suite.Queue task 1824 (repo-health-code-pilot), follow-up from triage task 1602.
Need help on this PR? Tag
@codesmith-botwith what you need.